﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PozrSvc.Controls
{
    public partial class ControlDebug : UserControl
    {
        public delegate void WriteLogDelegate(string s);
        public WriteLogDelegate WriteLog;

        public ControlDebug()
        {
            WriteLog = new WriteLogDelegate(Middleware_LogEvent_Invoke);
            Middleware.LogEvent += new LogEventHandler(Middleware_LogEvent);
            InitializeComponent();
            RefreshDbView();
        }

        void Middleware_LogEvent(string s)
        {
            this.Invoke(WriteLog, new Object[] { s });
        }

        void Middleware_LogEvent_Invoke(string s)
        {
            textBoxDebug.Text += "\r\n[" + DateTime.Now.ToLongTimeString() + "]" + s;
            textBoxDebug.SelectionStart = textBoxDebug.Text.Length;
            textBoxDebug.ScrollToCaret();
        }

        public void RefreshDbView()
        {
            dataGridTest.DataSource = Middleware.Database.GetPairs();
            dataGridTest.Refresh();
        }

        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            RefreshDbView();
        }
    }
}
